package com.ship.dispatch.controller;


import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import com.alibaba.cloud.commons.lang.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.github.pagehelper.PageInfo;
import com.ship.common.core.base.Page;
import com.ship.common.core.domain.R;
import com.ship.common.core.exception.BusException;
import com.ship.common.core.exception.ServiceException;
import com.ship.common.core.utils.FileUtils;
import com.ship.common.core.web.domain.BaseResultCode;
import com.ship.common.core.web.domain.JsonResult;
import com.ship.common.log.annotation.Log;
import com.ship.common.log.enums.BusinessType;
import com.ship.common.security.utils.SecurityUtils;
import com.ship.dispatch.bean.SpBoastPortMessage;
import com.ship.dispatch.bean.boats.*;
import com.ship.dispatch.bean.SpBoatsActualCompatible;
import com.ship.dispatch.bean.boats.info.*;
import com.ship.dispatch.bean.fob.SpFobFileRecord;
import com.ship.dispatch.model.Vo.SpBoatsActualCompatibleSaveVo;
import com.ship.dispatch.model.dto.*;
import com.ship.dispatch.service.BoastPortMessageService;
import com.ship.dispatch.service.ExportService;
import com.ship.dispatch.service.SpBoatsActualCompatibleService;
import com.ship.dispatch.service.fob.SpFobFileRecordService;
import com.ship.dispatch.vo.SpBoastPortMessageDetailVo;
import com.ship.dispatch.vo.SpBoastPortMessageExportVo;
import com.ship.dispatch.vo.SpBoastPortMessageVo;
import com.ship.system.api.RemoteFileService;
import com.ship.system.api.domain.SysFile;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/ship/shore/compatibility")
@Api(value = "shipShoreCompatibility", tags = "船岸兼容")
public class ShipShoreCompatibilityController {
    private static final Logger logger = LoggerFactory.getLogger(ShipShoreCompatibilityController.class);

    @Autowired
    private SpBoatsActualCompatibleService spBoatsActualCompatibleService;
    @Autowired
    private ExportService exportService;

    @Autowired
    private BoastPortMessageService boastPortMessageService;

    @Autowired
    private RemoteFileService remoteFileService;

    @Autowired
    SpFobFileRecordService spFobFileRecordService;

    /**
     * 港口挂靠船舶列表
     *
     * @return
     */
    @PostMapping("/boastPortMessage/page")
    @ApiOperation(value = "港口挂靠船舶列表")
    public JsonResult getBoastPortMessages(@RequestBody SpBoastPortMessageDto boastPortMessageDto) {
        PageInfo<SpBoastPortMessageVo> page = spBoatsActualCompatibleService.getBoastPortMessages(boastPortMessageDto);
        return JsonResult.success(page);
    }

    /**
     * 实际船岸兼容列表
     *
     * @return
     */
    @PostMapping("/page")
    @ApiOperation(value = "实际船岸兼容列表")
    public JsonResult<PageInfo<QueryBoatsActualCompatibleInfo>> getBoatsActualCompatible(@RequestBody QueryBoatsActualRq rq) {
        PageInfo<QueryBoatsActualCompatibleInfo> pageInfo = spBoatsActualCompatibleService.queryBoatsActualList(rq);
        return JsonResult.success(pageInfo);
    }

    @ApiOperation("导出实际船岸兼容信息")
    @PostMapping("/export/boatsActualCompatible")
    public JsonResult exportBoatsActualCompatible(@RequestBody SpBoatsActualCompatible boatsActualCompatible) {
        QueryWrapper queryWrapper = new QueryWrapper<>();
        if (boatsActualCompatible.getIds() != null && boatsActualCompatible.getIds().size() > 0) {
            queryWrapper.in("id", boatsActualCompatible.getIds());
        }
        List<QueryBoatsActualCompatibleInfo> exportList = spBoatsActualCompatibleService.exportBoatsActualCompatible(boatsActualCompatible);
        if (CollectionUtil.isNotEmpty(exportList)){
            exportList.forEach(item -> {
                if ("1".equals(item.getIsShipShoreCompatibility())){
                    item.setIsShipShoreCompatibility("是");
                }else if ("2".equals(item.getIsShipShoreCompatibility())){
                    item.setIsShipShoreCompatibility("否");
                }else if ("3".equals(item.getIsShipShoreCompatibility())){
                    item.setIsShipShoreCompatibility("有条件");
                }
            });
        }
        List<String> tableNameList = new ArrayList<>();
        tableNameList.add("shipName");
        tableNameList.add("voyageNo");
        tableNameList.add("portName");
        tableNameList.add("shipCompatibleDate");
        tableNameList.add("isShipShoreCompatibility");
        tableNameList.add("createDate");
        tableNameList.add("createUser");
        List<String> tableList = new ArrayList<>();
        tableList.add("船舶名称");
        tableList.add("航次号");
        tableList.add("港口名称");
        tableList.add("船岸兼容时间");
        tableList.add("船岸是否兼容");
        tableList.add("操作时间");
        tableList.add("操作人");
        Field[] fields = QueryBoatsActualCompatibleInfo.class.getDeclaredFields();
        String url = exportService.exportUtil(exportList, fields,
                tableNameList, tableList, "实际船岸兼容信息");
        return JsonResult.success(url);
    }

    @ApiOperation("根据类型查询搜索条件列表")
    @GetMapping("/query/message")
    public JsonResult queryMessage(@RequestParam String type) {
        List<String> messageList = boastPortMessageService.queryMessage(type);
        return JsonResult.success(messageList);
    }

    @ApiOperation("根据船舶名称查询所有船舶及接收站列表")
    @GetMapping("/query/postName/list")
    public JsonResult queryPostNameList(@RequestParam(required = false) String postName){
        List<String> messageList = boastPortMessageService.queryPostNameList(postName);
        return JsonResult.success(messageList);
    }

    @ApiOperation("分页查询船舶挂靠港记录列表")
    @PostMapping("/query/boatsPort/list")
    public JsonResult queryBoatsPortList(@RequestBody QueryBoatsPortRq rq) {
        logger.info("分页查询船舶挂靠港记录入参:{}" + JSONUtil.parse(rq));
        PageInfo<QueryBoatsPortInfo> pageInfo = boastPortMessageService.queryBoatsPortList(rq);
        logger.info("分页查询船舶挂靠港记录返回结果:{}" + JSONUtil.parse(pageInfo));
        return JsonResult.success(pageInfo);
    }

    @ApiOperation("导出船舶挂靠港记录")
    @PostMapping("/export/boatsPort")
    public JsonResult exportBoatsPort(@RequestBody QueryBoatsPortRq rq) throws IOException, IllegalAccessException {
        logger.info("导出船舶挂靠港记录入参:{}" + JSONUtil.parse(rq));
        List<QueryBoatsPortInfo> list = boastPortMessageService.exportBoatsPort(rq);
        List<String> tableNameList = new ArrayList<>();
        tableNameList.add("shipName");
        tableNameList.add("imo");
        tableNameList.add("portOfCallNumber");
        tableNameList.add("portOfCallNumberTotal");
        tableNameList.add("portNameTop1");
        tableNameList.add("portNameTop2");
        tableNameList.add("portNameTop3");
        tableNameList.add("portNameTop4");
        tableNameList.add("portNameTop5");
        List<String> tableList = new ArrayList<>();
        tableList.add("船舶名称");
        tableList.add("IMO");
        tableList.add("挂靠港数量");
        tableList.add("累计挂靠港次数");
        tableList.add("TOP1港口");
        tableList.add("TOP2港口");
        tableList.add("TOP3港口");
        tableList.add("TOP4港口");
        tableList.add("TOP5港口");
        Field[] fields = QueryBoatsPortInfo.class.getDeclaredFields();
        String url = exportService.fileExport(list, fields,
                tableNameList, tableList,
                "船舶挂靠港记录列表");
        return JsonResult.success(url);
    }

    @ApiOperation("根据imo号查询船舶挂靠港详情")
    @GetMapping("/query/boatsPort/byImo")
    public JsonResult queryBoatsPortByImo(@RequestParam String imo) {
        QueryBoatsPortDetailsInfo boatsPortDetails = boastPortMessageService.queryBoatsPortByImo(imo);
        logger.info("根据imo=" + imo + " 查询船舶挂靠港详情返回结果:{}" + boatsPortDetails);
        return JsonResult.success(boatsPortDetails);
    }

    @ApiOperation("根据imo分页查询船舶挂靠港汇总列表")
    @PostMapping("/query/boatsPortDetails/list")
    public JsonResult queryBoatsPortDetailsList(@RequestBody QueryBoatsPortDetailsRq rq) {
        logger.info("根据imo号分页查询船舶挂靠港详情列表入参:{}" + JSONUtil.parse(rq));
        PageInfo<QueryPortInfo> pageInfo = boastPortMessageService.queryBoatsPortDetailsList(rq);
        logger.info("根据imo号分页查询船舶挂靠港详情列表返回结果:{}" + JSONUtil.parse(pageInfo));
        return JsonResult.success(pageInfo);
    }

    @ApiOperation("根据imo导出船舶挂靠汇总列表")
    @PostMapping("/export/boatsPortDetails")
    public JsonResult exportBoatsPortDetails(@RequestBody QueryBoatsPortDetailsRq rq) {
        logger.info("根据imo导出船舶挂靠汇总列表入参:{}" + JSONUtil.parse(rq));
        List<QueryPortInfo> list = boastPortMessageService.exportBoatsPortDetails(rq);
        String shipName = boastPortMessageService.queryShipNameByImo(rq.getImo());
        List<String> tableNameList = new ArrayList<>();
        tableNameList.add("portNameEn");
        tableNameList.add("number");
        List<String> tableList = new ArrayList<>();
        tableList.add("港口名称");
        tableList.add("挂靠港次数");
        Field[] fields = QueryPortInfo.class.getDeclaredFields();
        String url = exportService.exportUtil(list, fields,
                tableNameList, tableList,
                shipName + "挂靠港记录");
        return JsonResult.success(url);
    }

    @ApiOperation("根据imo号分页查询挂靠船姊妹船详情列表")
    @PostMapping("/query/boatsPortSister/list")
    public JsonResult queryBoatsPortSisterList(@RequestBody QueryPortSisterRq rq) {
        logger.info("根据imo号分页查询船舶挂靠港详情姊妹船列表入参:{}" + JSONUtil.parse(rq));
        List<QueryBoatsPortSisterInfo> boatsPortSisterList = boastPortMessageService.queryBoatsPortSisterList(rq);
        logger.info("根据imo号分页查询船舶挂靠港详情姊妹船列表入参:{}" + JSONUtil.parse(boatsPortSisterList));
        return JsonResult.success(boatsPortSisterList);
    }

    @ApiOperation("根据imo号导出挂靠姊妹船列表")
    @PostMapping("/export/boatsPortSister")
    public JsonResult exportBoatsPortSisterList(@RequestBody QueryPortSisterRq rq) {
        logger.info("根据imo号导出挂靠姊妹船列表入参:{}" + JSONUtil.parse(rq));
        List<QueryBoatsPortSisterInfo> list = boastPortMessageService.exportBoatsPortSisterList(rq);
        String shipName = boastPortMessageService.queryShipNameByImo(rq.getImo());
        List<String> tableNameList = new ArrayList<>();
        tableNameList.add("shipName");
        tableNameList.add("sisterImo");
        List<String> tableList = new ArrayList<>();
        tableList.add("船舶名称");
        tableList.add("IMO");
        Field[] fields = QueryBoatsPortSisterInfo.class.getDeclaredFields();
        String url = exportService.exportUtil(list, fields,
                tableNameList, tableList,
                shipName + "姊妹船信息");
        return JsonResult.success(url);
    }

    @ApiOperation("根据imo号分页查询详情挂靠港历史记录")
    @PostMapping("/query/boatsPortHistory/list")
    public JsonResult queryBoatsPortHistoryList(@RequestBody QueryBoatsPortHistoryRq rq) {
        logger.info("根据imo号分页查询船舶挂靠港详历史入参:{}" + JSONUtil.parse(rq));
        PageInfo<SpBoastPortMessage> pageInfo = boastPortMessageService.queryBoatsPortHistoryList(rq);
        logger.info("根据imo号分页查询船舶挂靠港详历史入参:{}" + JSONUtil.parse(pageInfo));
        return JsonResult.success(pageInfo);
    }

    @ApiOperation("导出船舶历史挂靠港记录")
    @PostMapping("/export/boatsPortHistory")
    public JsonResult exportBoatsPortHistory(@RequestBody QueryBoatsPortHistoryRq rq) {
        logger.info("导出船舶历史挂靠港记录入参:{}" + JSONUtil.parse(rq));
        List<SpBoastPortMessage> boastPortMessageList = boastPortMessageService.exportBoatsPortHistory(rq);
        String shipName = boastPortMessageService.queryShipNameByImo(rq.getImo());
        List<String> tableNameList = new ArrayList<>();
        tableNameList.add("portNameEn");
        tableNameList.add("portCode");
        tableNameList.add("countryChs");
        tableNameList.add("timeZone");
        tableNameList.add("inTime");
        tableNameList.add("inPortDraught");
        tableNameList.add("layUpTime");
        tableNameList.add("outPortDraught");
        List<String> tableList = new ArrayList<>();
        tableList.add("港口名称");
        tableList.add("港口代码");
        tableList.add("国家或地区");
        tableList.add("时区");
        tableList.add("到港时间");
        tableList.add("抵港吃水(米)");
        tableList.add("靠泊时间");
        tableList.add("离港吃水(米)");
        Field[] fields = SpBoastPortMessage.class.getDeclaredFields();
        String url = exportService.exportUtil(boastPortMessageList, fields,
                tableNameList, tableList,
                shipName + "历史挂靠港记录");
        return JsonResult.success(url);
    }

    @ApiOperation("导出港口挂靠船舶记录")
    @PostMapping("/export/boatsPortMessage")
    public JsonResult exportBoastPortMessages(@RequestBody SpBoastPortMessageDto boastPortMessageDto) {
        PageInfo<SpBoastPortMessageVo> page = spBoatsActualCompatibleService.getBoastPortMessages(boastPortMessageDto);
        List<SpBoastPortMessageVo> list = new ArrayList<>();
        if (null != page && page.getSize() > 0) {
            list = page.getList();
        }
        List<String> tableNameList = new ArrayList<>();
        tableNameList.add("portNameEn");
        tableNameList.add("portCode");
        tableNameList.add("shipNum");
        tableNameList.add("totalNum");
        tableNameList.add("shipTopOne");
        tableNameList.add("shipTopTwo");
        tableNameList.add("shipTopThird");
        tableNameList.add("shipTopFourth");
        tableNameList.add("shipTopFifth");
        List<String> tableList = new ArrayList<>();
        tableList.add("港口名称");
        tableList.add("港口代码");
        tableList.add("挂靠船舶数量");
        tableList.add("TOP1船舶");
        tableList.add("TOP2船舶");
        tableList.add("TOP3船舶");
        tableList.add("TOP4船舶");
        tableList.add("TOP5船舶");
        Field[] fields = SpBoastPortMessageVo.class.getDeclaredFields();
        String url = exportService.exportUtil(list, fields,
                tableNameList, tableList,
                "港口挂靠船舶记录列表");
        return JsonResult.success(url);
    }

    @ApiOperation("根据港口名查询港口挂靠船舶详情")
    @GetMapping("/query/boatsPort/byPortName")
    public JsonResult getBoastPortMessageDetail(@RequestParam String portNameChs) {
        SpBoastPortMessageDetailVo boastPortMessageDetailVo = boastPortMessageService.getBoastPortMessageDetail(portNameChs);
        return JsonResult.success(boastPortMessageDetailVo);
    }

    @ApiOperation("给港口挂靠船舶上传相关文件")
    @PostMapping("/query/boatsPortUpFile/byPortName")
    public JsonResult getBoatsPortUpileMessageDetail(@RequestParam("file") MultipartFile file, String portNameChs,@RequestParam(required = false) String type) {
        FileUtils.checkFileName(file);
        String result = boastPortMessageService.upload(file, portNameChs,type);
        return JsonResult.success(result);
    }

    @ApiOperation("根据港口名查询港口挂靠船舶相关文件")
    @GetMapping("/query/boatsPortFile/byPortName")
    public JsonResult getBoatsPortFileMessageDetail(@RequestParam String portNameChs,@RequestParam(required = false) String type) {
        List<Map<String, String>> result = boastPortMessageService.getBoastPortFileMessageDetail(portNameChs,type);
        return JsonResult.success(result);
    }

    @ApiOperation("删除港口挂靠船舶相关文件")
    @DeleteMapping("/query/delBoatsPortFile/byPortName")
    public JsonResult delete(@RequestParam Long id) {
        String result = boastPortMessageService.delBoatsPortFile(id);
        return JsonResult.success(result);
    }

    @ApiOperation("导出港口挂靠船舶相关文件")
    @GetMapping("/query/exportBoatsPortFile/byPortName")
    public JsonResult getExportBoatsPortFileMessageDetail(@RequestParam String id) {
        String result = boastPortMessageService.getUrl(id);
        return JsonResult.success(result);
    }

    @ApiOperation("根据港口名查询港口挂靠船舶详情历史记录")
    @PostMapping("/getBoatsPortHistoryList/list")
    public JsonResult getBoatsPortHistoryList(@RequestBody SpBoastPortMessageShipDetailDto boastPortMessageShipDetailDto) {
        PageInfo<SpBoastPortMessage> pageInfo = boastPortMessageService.getBoatsPortHistoryList(boastPortMessageShipDetailDto);
        return JsonResult.success(pageInfo);
    }

    @ApiOperation("导出港口挂靠船舶详情历史记录")
    @PostMapping("/export/boatsPortHistoryDetailList")
    public JsonResult exportBoatsPortHistoryDetailList(@RequestBody SpBoastPortMessageDetailDto boastPortMessageDetailDto) {
        List<SpBoastPortMessageExportVo> list = boastPortMessageService.exportBoatsPortHistoryDetailList(boastPortMessageDetailDto);
        List<String> tableNameList = new ArrayList<>();
        tableNameList.add("shipName");
        tableNameList.add("imo");
        tableNameList.add("inTime");
        tableNameList.add("inPortDraught");
        tableNameList.add("layUpTime");
        tableNameList.add("outPortDraught");
        List<String> tableList = new ArrayList<>();
        tableList.add("船舶名称");
        tableList.add("IMO");
        tableList.add("到港时间");
        tableList.add("抵港吃水(米)");
        tableList.add("靠泊时间");
        tableList.add("离港吃水(米)");
        Field[] fields = SpBoastPortMessageExportVo.class.getDeclaredFields();
        String url = exportService.exportUtil(list, fields,
                tableNameList, tableList,
                "港口挂靠船舶详情历史记录");
        return JsonResult.success(url);
    }

    @ApiOperation("新增实际船岸兼容")
    @PostMapping("/saveBoatsActualCompatibility")
    public JsonResult saveBoatsActualCompatibility(@RequestBody BoatsActualCompatibilitySaveDto boatsActualCompatibilitySaveDto) {
        SpBoatsActualCompatible boatsActualCompatible = spBoatsActualCompatibleService.saveBoatsActualCompatibility(boatsActualCompatibilitySaveDto);
        if (null != boatsActualCompatible) {
            SpFobFileRecord spFobFileRecord = new SpFobFileRecord();
            spFobFileRecord.setActualShipId(boatsActualCompatible.getId());
            if(null != boatsActualCompatibilitySaveDto.getFileIds() && boatsActualCompatibilitySaveDto.getFileIds().size()>0){
                for (String fileId : boatsActualCompatibilitySaveDto.getFileIds()) {
                    spFobFileRecord.setId(Long.valueOf(fileId));
                    spFobFileRecordService.updateById(spFobFileRecord);
                }
            }
        }
        return JsonResult.success(boatsActualCompatible);
    }

    @ApiOperation("查看实际船岸兼容")
    @GetMapping("/getBoatsActualCompatibility/{id}")
    public JsonResult getBoatsActualCompatibility(@PathVariable Long id) {
        SpBoatsActualCompatibleSaveVo boatsActualCompatibleSaveVo = spBoatsActualCompatibleService.getBoatsActualCompatibility(id);
        if (null != boatsActualCompatibleSaveVo) {
            List<SpFobFileRecord> spFobFileRecords = spFobFileRecordService.list(new LambdaQueryWrapper<SpFobFileRecord>().eq(SpFobFileRecord::getActualShipId,boatsActualCompatibleSaveVo.getId()));
            if(null != spFobFileRecords && spFobFileRecords.size()>0){
                boatsActualCompatibleSaveVo.getFiles().addAll(spFobFileRecords);
            }
        }
        return JsonResult.success(boatsActualCompatibleSaveVo);
    }

    @ApiOperation("编辑实际船岸兼容")
    @PostMapping("/updateBoatsActualCompatibility")
    public JsonResult updateBoatsActualCompatibility(@RequestBody BoatsActualCompatibilityUpdateDto boatsActualCompatibilityUpdateDto) {
        SpBoatsActualCompatibleSaveVo boatsActualCompatibleSaveVo = spBoatsActualCompatibleService.updateBoatsActualCompatibility(boatsActualCompatibilityUpdateDto);
        if (null != boatsActualCompatibleSaveVo) {
            if(StringUtils.isNotBlank(boatsActualCompatibilityUpdateDto.getId())){
                if(boatsActualCompatibilityUpdateDto.getFileIds().size()>0){
                    spFobFileRecordService.getBaseMapper().delete(new LambdaQueryWrapper<SpFobFileRecord>()
                            .eq(SpFobFileRecord::getActualShipId,boatsActualCompatibilityUpdateDto.getId())
                            .eq(SpFobFileRecord::getFileType,"实际船岸兼容")
                            .notIn(SpFobFileRecord::getId,boatsActualCompatibilityUpdateDto.getFileIds()));
                }
                List<SpFobFileRecord> fileList = spFobFileRecordService.getBaseMapper().selectList(new LambdaQueryWrapper<SpFobFileRecord>()
                        .eq(SpFobFileRecord::getActualShipId, boatsActualCompatibilityUpdateDto.getId())
                        .eq(SpFobFileRecord::getFileType, "实际船岸兼容"));
                if (CollectionUtil.isNotEmpty(fileList)){
                    List<Long> fileIdList = fileList.stream().map(SpFobFileRecord::getId).collect(Collectors.toList());
                    boatsActualCompatibilityUpdateDto.getFileIds().forEach(item -> {
                        if (!fileIdList.contains(Long.valueOf(item))){
                            spFobFileRecordService.getBaseMapper().update(null,new LambdaUpdateWrapper<SpFobFileRecord>()
                                    .eq(SpFobFileRecord :: getId,item)
                                    .set(SpFobFileRecord :: getActualShipId,boatsActualCompatibilityUpdateDto.getId()));
                        }
                    });
                }else {
                    boatsActualCompatibilityUpdateDto.getFileIds().forEach(item -> {
                        spFobFileRecordService.getBaseMapper().update(null,new LambdaUpdateWrapper<SpFobFileRecord>()
                                .eq(SpFobFileRecord :: getId,item)
                                .set(SpFobFileRecord :: getActualShipId,boatsActualCompatibilityUpdateDto.getId()));
                    });
                }
            }
        }
        return JsonResult.success(boatsActualCompatibleSaveVo);
    }

    @ApiOperation("删除实际船岸兼容")
    @GetMapping("/delete/boatsActualCompatibilityById")
    public JsonResult deleteBoatsActualCompatibilityById(@RequestParam Long id){
        boolean status = spBoatsActualCompatibleService.deleteBoatsActualCompatibilityById(id);
        return JsonResult.success(status);
    }

    /**
     * 上传文件
     *
     * @param file
     * @return
     */
    @ApiOperation("上传实际船岸兼容附件")
    @PostMapping("/uploadFile")
    @Log(title = "上传文件", businessType = BusinessType.IMPORT)
    public JsonResult uploadFile(@RequestParam("file") MultipartFile file) {
        FileUtils.checkFileName(file);
        if (file.isEmpty()) {
            throw new IllegalArgumentException("上传的文件为空");
        }
        String name = file.getOriginalFilename();

        String url = upload(file);

        SpFobFileRecord spFobFileRecord = new SpFobFileRecord();
        spFobFileRecord.setPath(url);
        spFobFileRecord.setName(name);
        spFobFileRecord.setFileType("实际船岸兼容");

        spFobFileRecordService.save(spFobFileRecord);
        Long id = spFobFileRecord.getId();

        return JsonResult.success(id.toString());
    }

    /**
     * 上传附件M
     *
     * @return
     */
    public String upload(MultipartFile file) {
        FileUtils.checkFileName(file);
        R<SysFile> result1 = remoteFileService.upload(file);
        if (result1.getCode() != R.SUCCESS) {
            throw new BusException("文件服务器连接失败", BaseResultCode.GENERAL_ERROR);
        }
        String result = result1.getData().getHttpsUrl();
        ;
        return result;
    }
}
